import React,{useEffect} from 'react';
import styles from './index.less';
import {history,connect} from 'umi';

const Home = (props) => {
  // fetch('/api/tags')
  // .then(res=>res.json())
  // .then(res=>console.log(res))
  console.log(props.goodslist);
  useEffect(()=>{
    props.dispatch({
      type:'index/getList'
    })
  },[])
  return (
    <div>
      <h1 className={styles.title}>
        Page index
        <button onClick={
          ()=>history.push('/cart')
        }>to Cart</button>

        <h1>{props.username}</h1>
        <button
          onClick={()=>{
            props.dispatch({
              type:'index/login',
              username:'hello'
            })
          }}
        >登录</button>
      </h1>
    </div>
  );
}
const mapStateToProps = (state)=>({
  username: state.index.name,
  goodslist: state.index.goodslist
})
export default connect(mapStateToProps)(Home);